package com.plm.mr.writablecompable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, FlowBean, Text> {

    private FlowBean k = new FlowBean();
    private Text v = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 13470253144	180	180	360
        // 13509468723	7335	110349	117684
        //1 获取一行数据
        String line = value.toString();

        //2 按照"\t", 切割数据
        String[] split = line.split("\t");

        //3 封装 k v
        k.setUpFlow(Long.parseLong(split[1]));
        k.setDownFlow(Long.parseLong(split[2]));
        k.setSumFlow();
        v.set(split[0]);

        //4 写出 k v
        context.write(k, v);
    }
}
